package com.hbsx.why.ui.home;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hbsx.why.R;
import com.hbsx.why.base.BaseActivity;
import com.hbsx.why.views.ReboundScrollView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by User on 2017/8/30.
 */

public class BookDtailActivity extends BaseActivity {
    @BindView(R.id.venue_scrollView)
    ReboundScrollView venueScrollView;
    @BindView(R.id.tv_topTitle)
    TextView tvTopTitle;
    @BindView(R.id.venue_relayout)
    LinearLayout venueRelayout;

    @Override
    protected int getLayoutResId() {
        return R.layout.bookdetail_main;
    }

    @Override
    protected void initView() {
        tvTopTitle.setText("");
        venueScrollView.setOnScollChangedListener(new ReboundScrollView.OnScollChangedListener() {
            @Override
            public void onScrollChanged(ReboundScrollView scrollView, int x, int y, int oldx, int oldy) {
                if (y <= 0) { // 设置标题的背景颜色
                    venueRelayout.setBackgroundColor(getBgColor(0));
                    tvTopTitle.setText("");
                } else if (y > 0 && y <= venueRelayout.getHeight()) { // 滑动距离小于banner图的高度时，设置背景和字体颜色颜色透明度渐变
                    float scale = (float) y / venueRelayout.getHeight();
                    float alpha = (255 * scale);
                    venueRelayout.setBackgroundColor(getBgColor((int) alpha));

                } else { // 滑动到banner下面设置普通颜色
                    venueRelayout.setBackgroundColor(getBgColor(255));
                    tvTopTitle.setText("图书详情");
                }

            }
        });

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
    public int getBgColor(int alpha) {
        return Color.argb(alpha,
                28, 92, 164);
    }
}
